package com.gzsxy.sso.core.api.v1.config;

import com.gzsxy.sso.common.dto.request.UserRequest;
import com.gzsxy.sso.common.dto.response.DefaultResponse;
import com.gzsxy.sso.common.dto.response.UserRsp;

import com.gzsxy.sso.core.entity.User;
import com.gzsxy.sso.core.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 用户对外相关接口
 * @date 2022/2/16 10:17
 */
@Api(tags = "api_v1_用户相关接口")
@CrossOrigin  //解决跨域
@RestController
@RequestMapping("/api/v1/config/user")
public class UserApi {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    @ApiOperation("根据用户id查询用户")
    public DefaultResponse getUserById(@PathVariable String id){
        User user = userService.getUserById(id);
        return DefaultResponse.ok(user);
    }

    @ApiOperation("编辑用户")
    @PutMapping("/update")
    public DefaultResponse updateUser(@RequestBody UserRequest request){
        UserRsp user = userService.updateApiUser(request);
        return DefaultResponse.ok(user);
    }

    @ApiOperation("编辑账号余额")
    @GetMapping("/editAmount/{id}")
    public DefaultResponse editAmountById(@PathVariable String id,@RequestParam Integer amount){
        userService.editAmountById(id,amount);
        return DefaultResponse.ok();
    }

    @ApiOperation("添加账号并赋值该有的角色权限")
    @PostMapping("/add")
    public DefaultResponse addUser(@RequestBody UserRequest request){
        userService.addUser1(request);
        return DefaultResponse.ok();
    }

    @ApiOperation("获取当前所有注册的商家")
    @GetMapping("/getAllUserId")
    public DefaultResponse selectAllUserId(){
        List<String> userIdList = userService.selectAllUserId();
        return DefaultResponse.ok(userIdList);
    }



}
